<template>
    <div>
        <h1>显示</h1>
        房间名称<input type="text" v-model="info.names">
        状态<select v-model="info.state">
                <option value="">请选择</option>
                <option value="true">启用</option>
                <option value="false">停用</option>
        </select>
        <input type="button" value="查询" @click="getlist()">
        <input type="button" value="重置" @click="rest">
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>Id</td>
                    <td>房间名称</td>
                    <td>门市销售价格</td>
                    <td>房间数</td>
                    <td>状态</td>
                    <td>房间号</td>
                    <td>操作</td>
                </tr>

                <tr v-for="itme in data.list":key="itme.Id">
                    <td>{{ itme.Id }}</td>
                    <td>{{ itme.Name }}</td>
                    <td>￥{{ itme.Price }}</td>
                    <td>{{ itme.Num }}</td>
                    <td>{{ itme.State?"启用":"停用" }}</td>
                    <td>{{ itme.NumBer }}</td>
                    <td>
                        <input type="button" value="删除" @click="del(itme.Id)">
                        <input type="button" value="修改" @click="xg(itme.Id)"></td>
                </tr>
            </tbody>
        </table>
        <span><b>共{{ data.totalcount }}条</b></span>
        <span><b>每页{{ info.pagesize }}条</b></span>
        <span><b>共 {{ info.pageindex }}/{{ data.totalpage }}页</b></span>
        <input type="button" value="首页" @click="gopage(1)">
        <input type="button" value="上一页" @click="gopage(info.pageindex-1)">
        <span v-for="itme in data.totalpage" @click="gopage(itme)">
            {{ itme }}
        </span>
        <input type="button" value="下一页" @click="gopage(info.pageindex+1)">
        <input type="button" value="尾页" @click="gopage(data.totalpage)">
        <input type="number"  @click="info.pageindex">
        <input type="button" value="跳转" @click="gopage(data.totalpage)">
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue'
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
const router=useRouter();
const route=useRoute();
let info:any=reactive({
  names: '',
  state: '',
  pageindex:1,
  pagesize:2
})

let data:any=reactive({
    list:[],
    totalcount:0,
    totalpage:0,
})
onMounted(()=>{
    getlist();
})
const rest=()=>
{
   info.names= '';
  info.state= '';
};
const getlist=()=>{
    axios({
        url:'/api/User/Query',
        method:'get',
        params:info
    })
    .then((res)=>{
        console.log(res);
        Object.assign(data,res.data)
    })
    .catch((err)=>{
        console.log(err);
        
    })
}
//==========================分页=======================
const show=()=>{
    info.pageindex=1,
    getlist();
}
const gopage=(num:any)=>{
    if(num<1)
    {
        info.pageindex=1;
        return;
    }   
    if(info.pageindex>data.totalpage)
    {
        info.pageindex>data.totalpage;
        return;
    }
    info.pageindex=num;
    getlist();
}
//=============================修改=====================
const xg=(id:any)=>
{
    router.push({
        path:'/xg',
        query:{id:id}
    })
}
//=============================删除=====================
const del=(id:any)=>{
    let f:any=ref([
        alert('确认删除吗')
    ])
    if(f)
{
    axios({
        url:'/api/User/Del',
        method:'delete',
        params:{id:id}
    })
    .then((res)=>{
        console.log(res);
        if(res.data>0)
    {
        alert("删除成功")
        return
    }
    else{
        alert("删除失败")
        return
    }
    })
    .catch((err)=>{
        console.log(err);
        
    })
}
    
}
</script>

<style scoped>
span{
    margin: 10px;
}
</style>